﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.SolveLoops.ViewModels.CApSolveLoopsShellViewModel
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands.SolveLoops.ViewModels;

public class CApSolveLoopsShellViewModel : TxViewModelBase
{
  public CApSolveLoopsViewModel SolveLoopsVM { get; set; }

  public TxWindowCommand<TxWindow> OKCommand { get; set; }

  public TxWindowCommand<TxWindow> CancelCommand { get; set; }

  public CApSolveLoopsShellViewModel()
  {
    this.SolveLoopsVM = new CApSolveLoopsViewModel();
    this.OKCommand = new TxWindowCommand<TxWindow>(new Action<TxWindow>(this.Apply), new Func<bool>(this.CanApply));
    this.CancelCommand = new TxWindowCommand<TxWindow>(new Action<TxWindow>(this.Close));
  }

  private void Close(TxWindow window)
  {
    List<TxJoint> joints = new List<TxJoint>();
    foreach (object selectedJoint in (IEnumerable) this.SolveLoopsVM.SelectedJoints)
      joints.Add((selectedJoint as DataGridItem).JointObject);
    new CApSolveLoopsLogic(this.SolveLoopsVM.SelectedLink, joints).Execute();
    ((Window) window)?.Close();
  }

  private bool CanApply()
  {
    if (!TxKinematicLink.op_Inequality(this.SolveLoopsVM.SelectedLink, (ITxObject) null))
      return false;
    IList selectedJoints = this.SolveLoopsVM.SelectedJoints;
    return selectedJoints != null && selectedJoints.Count > 0;
  }

  private void Apply(TxWindow window) => this.Close(window);
}
